package com.gateio.flutter.lib_furnace

import android.util.Log
import androidx.annotation.NonNull

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result

/** GTLibFurnaceFlutterPlugin */
class GTLibFurnaceFlutterPlugin: FlutterPlugin, GTFurnaceHostApiV2 {

  override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
    Log.d("GTFlutter", "GTLibFurnaceFlutterPlugin onAttachedToEngine.")
    GTFurnaceHostApiV2.setUp(flutterPluginBinding.binaryMessenger, this)
  }

  override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
    Log.d("GTFlutter", "GTLibFurnaceFlutterPlugin onDetachedFromEngine.")
    GTFurnaceHostApiV2.setUp(binding.binaryMessenger, null)
  }

  override fun addStartPageName(routeName: String?) {
    routeName?.let {
      if (GTFlutter.pageStartedList.contains(routeName)) {
        GTFlutter.pageStartedList.remove(routeName)
      }
      GTFlutter.pageStartedList.add(routeName)
    }
  }

  override fun removeStartPage(routeName: String?) {
    routeName?.let {
      GTFlutter.pageStartedList.remove(routeName)
    }
  }

}
